package com.dream.keigezhushou.Activity.acty.listen.golden;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.dream.keigezhushou.Activity.acty.listen.myview.AlertDialog;
import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.Activity.adapter.HomeAdapter;
import com.dream.keigezhushou.Activity.pop.MoreWindow;
import com.dream.keigezhushou.Activity.pop.MoreWindowToMusicMessage;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.Activity.view.ItemRemoveRecylerView30sMyCollected;
import com.dream.keigezhushou.Activity.view.OnItemClickListener;
import com.dream.keigezhushou.Activity.wigdt.DividerItemDeoration;
import com.dream.keigezhushou.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Golde30MyCollectedActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_collect)
    ItemRemoveRecylerView30sMyCollected lvCollect;
    @BindView(R.id.ivBBAlbum)
    CircleImageView ivBBAlbum;
    @BindView(R.id.tvBBTitle)
    TextView tvBBTitle;
    @BindView(R.id.tvBBSinger)
    TextView tvBBSinger;
    @BindView(R.id.ib_Next)
    ImageView ibNext;
    @BindView(R.id.ib_Play_pause)
    ImageView ibPlayPause;
    @BindView(R.id.ib_previous)
    ImageView ibPrevious;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.rlBottomBar)
    RelativeLayout rlBottomBar;
    @BindView(R.id.activity_golde30_my_collected)
    LinearLayout activityGolde30MyCollected;
    private HomeAdapter mAdater;
    private PopupWindow mPopWindow;
    private List<String> mDatas;

    public final View contentView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_golde30_my_collected);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        if (intent != null) {
            String value2 = intent.getStringExtra("state");
            tvTitle.setText(value2);
        }
        initView();

    }

    //初始化界面
    protected void initView() {

        initData();

//        tvTitle.setText("挑歌历史");

        mAdater = new HomeAdapter(this, mDatas);
        lvCollect.setAdapter(mAdater);

        lvCollect.addItemDecoration(new DividerItemDeoration(this, DividerItemDeoration.VERTICAL_LIST));
//        lvCollect = (RecyclerView) findViewById(R.id.gold_collected_recycleview);
        lvCollect.setLayoutManager(new LinearLayoutManager(this));

mAdater.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {

    }

    @Override
    public void onDeleteClick(int mPosition) {

    }

    @Override
    public void onItemMoreClick(int position) {

        final MoreWindow moreWindow = new MoreWindow(View.inflate(Golde30MyCollectedActivity.this, R.layout.golde30s_pupwindow, null), Golde30MyCollectedActivity.this, RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
        moreWindow.showPopAtLocation(lvCollect, Gravity.BOTTOM);
        moreWindow.setItemListener(new MoreWindow.ItemClickListener() {
            @Override
            public void onClick() {
//                        Toast.makeText(HotRecommendActivity.this, "好样", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onSingDetail() {


                WindowManager wm = (WindowManager) Golde30MyCollectedActivity.this
                        .getSystemService(Context.WINDOW_SERVICE);

                int width = wm.getDefaultDisplay().getWidth();
                int height = wm.getDefaultDisplay().getHeight();


                MoreWindowToMusicMessage moreWindowToMusicMessage = new MoreWindowToMusicMessage(View.inflate(Golde30MyCollectedActivity.this, R.layout.pop_musicmessage, null), Golde30MyCollectedActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
//                       moreWindow.setBackColorState(0);
                moreWindowToMusicMessage.showPopAtLocation(lvCollect, Gravity.BOTTOM);
                moreWindow.backGroundAlpha(0.4f);


            }
        });


    }
});


        mAdater.addHeadView(View.inflate(this, R.layout.golde30s_collecte_headerview, null));
        mAdater.addFootView(View.inflate(this, R.layout.golde30s_collecte_footview, null));

        lvCollect.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(Golde30MyCollectedActivity.this, "item", Toast.LENGTH_SHORT).show();


            }

            @Override
            public void onDeleteClick(final int mPosition) {
                if (mPosition > 0) {
                    DisplayMetrics metric = new DisplayMetrics();
                    getWindowManager().getDefaultDisplay().getMetrics(metric);
                    int width = (int) (metric.widthPixels * 0.6);
//                    int height = (int) (metric.heightPixels);
                    AlertDialog myalerdialog = new AlertDialog(View.inflate(Golde30MyCollectedActivity.this, R.layout.alertdialog, null), Golde30MyCollectedActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
                    myalerdialog.showPopAtLocation(lvCollect, Gravity.CENTER_HORIZONTAL);

                    myalerdialog.setItemListener(new AlertDialog.ItemClickListener() {
                        @Override
                        public void onClick() {


                            mAdater.removeItem(mPosition - 1);

                        }


                    });
                }
            }

            @Override
            public void onItemMoreClick(int position) {

            }
        });

    }

    //初始化数据
    protected void initData() {

        ivReturn.setOnClickListener(this);

        mDatas = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++) {
            mDatas.add("" + (char) i);
        }
    }

    public void backGroundAlpha(float alp) {
        WindowManager.LayoutParams lParams = this
                .getWindow().getAttributes();
        lParams.alpha = alp;
        this.getWindow().setAttributes(lParams);

    }


    public interface MyItemClickListener {
        public void onItemClick(int position);

        public void onBtnClick(int position);
    }


    //点击事件的实现

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.iv_return:

                //返回
                finish();
                break;
        }
    }
}
